/*     */ package com.iris.egrant.web.struts2.tags;
/*     */ 
/*     */ import java.io.IOException;
/*     */ import java.io.UnsupportedEncodingException;
/*     */ import java.net.URLEncoder;
/*     */ import java.util.Enumeration;
/*     */ import java.util.StringTokenizer;
/*     */ import java.util.regex.Pattern;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.jsp.JspTagException;
/*     */ import javax.servlet.jsp.tagext.BodyTagSupport;
/*     */ 
/*     */ public class PagerTag
/*     */   extends BodyTagSupport
/*     */ {
/*  16 */   private final String PAGE_NO = "page";
/*     */   
/*  18 */   private final String PAGE_SIZE = "rows";
/*     */   
/*  20 */   private final String PAGE_COUNT = "pageCount";
/*     */   
/*  22 */   private final String TOTAL = "total";
/*     */   
/*  24 */   private int pageNo = 0;
/*     */   
/*  26 */   private int pageSize = 0;
/*     */   
/*  28 */   private int pageCount = 0;
/*     */   
/*  30 */   private int total = 0;
/*     */   
/*  32 */   private int defaultPageSize = 20;
/*     */   
/*  34 */   private String action = null;
/*     */   
/*  36 */   private String navigatorType = "TEXT";
/*     */ 
/*     */ 
/*     */   
/*     */   private StringBuffer output;
/*     */ 
/*     */ 
/*     */   
/*     */   private boolean toExcel = true;
/*     */ 
/*     */ 
/*     */   
/*     */   private boolean showExcelHref = false;
/*     */ 
/*     */ 
/*     */   
/*     */   public void setAction(String action) {
/*  53 */     this.action = action;
/*     */   }
/*     */   
/*     */   public void setTotal(int total) {
/*  57 */     this.total = total;
/*     */   }
/*     */   
/*     */   public void setDefaultPageSize(int defaultPageSize) {
/*  61 */     this.defaultPageSize = defaultPageSize;
/*  62 */     this.pageSize = defaultPageSize;
/*     */   }
/*     */   
/*     */   public void setNavigatorType(String navigatorType) {
/*  66 */     this.navigatorType = navigatorType;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public int doStartTag() throws JspTagException {
/*     */     try {
/*  74 */       this.output = new StringBuffer();
/*  75 */       handler();
/*  76 */       this.pageContext.getOut().write(this.output.toString());
return 0;
/*  78 */     } catch (IOException ioe) {
/*  79 */       throw new JspTagException(ioe.getMessage());
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public int doEndTag() throws JspTagException {
/*  87 */     return 6;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private void handler() throws JspTagException {
/*  95 */     HttpServletRequest request = (HttpServletRequest)this.pageContext.getRequest();
/*     */     
/*  97 */     if (this.action == null) {
/*  98 */       this.action = trimURIParameter(request.getRequestURI());
/*     */     }
/*     */     
/* 101 */     if (this.total == 0 || this.pageSize == 0) {
/* 102 */       this.pageCount = 0;
/* 103 */       this.pageNo = 0;
/*     */     } else {
/*     */       
/* 106 */       this.pageCount = (this.total % this.pageSize == 0) ? (this.total / this.pageSize) : (this.total / this.pageSize + 1);
/*     */ 
/*     */       
/* 109 */       String strPageNo = request.getParameter("page");
/* 110 */       if (strPageNo == null) {
/* 111 */         this.pageNo = 1;
/* 112 */       } else if (Pattern.compile("^\\d+$").matcher(strPageNo).matches()) {
/* 113 */         if (strPageNo.length() > 8) {
/* 114 */           this.pageNo = this.pageCount;
/*     */         } else {
/* 116 */           this.pageNo = Integer.parseInt(strPageNo);
/*     */         } 
/*     */       } else {
/* 119 */         this.pageNo = 1;
/*     */       } 
/*     */     } 
/*     */ 
/*     */ 
/*     */     
/* 125 */     if (this.pageNo > this.pageCount)
/* 126 */       this.pageNo = this.pageCount; 
/* 127 */     if (this.pageNo <= 0) {
/* 128 */       this.pageNo = 1;
/*     */     }
/* 130 */     this.output.append(getNavigatorBar(this.navigatorType));
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private String getNavigatorBar(String type) {
/* 142 */     HttpServletRequest request = (HttpServletRequest)this.pageContext.getRequest();
/*     */     
/* 144 */     String bar = "\n";
/* 145 */     String nextDisabled = "";
/* 146 */     String prevDisabled = "";
/*     */     
/* 148 */     if (this.pageNo >= this.pageCount)
/* 149 */       nextDisabled = "disabled"; 
/* 150 */     if (this.pageNo <= 1) {
/* 151 */       prevDisabled = "disabled";
/*     */     }
/*     */     
/* 154 */     if (type.equalsIgnoreCase("TEXT")) {
/*     */       
/* 156 */       StringBuffer firstText = new StringBuffer("[首 &nbsp;页]");
/* 157 */       StringBuffer prevText = new StringBuffer("上一页");
/* 158 */       StringBuffer nextText = new StringBuffer("下一页");
/* 159 */       StringBuffer lastText = new StringBuffer("[尾 &nbsp;页]");
/*     */       
/* 161 */       if (prevDisabled.equalsIgnoreCase("")) {
/* 162 */         firstText.delete(0, firstText.length());
/* 163 */         firstText.append("<a class=a-but style=\"cursor:pointer\"");
/* 164 */         firstText.append(" onclick=\"goPage(window.location.href,1);");
/* 165 */         firstText.append(" \" >");
/* 166 */         firstText.append("[首 &nbsp;页]");
/* 167 */         firstText.append("</a>");
/* 168 */         prevText.delete(0, prevText.length());
/* 169 */         prevText.append("<a class=a-but style=\"cursor:pointer\"");
/* 170 */         prevText.append(" onclick=\"goPage(window.location.href,");
/* 171 */         prevText.append(this.pageNo - 1);
/* 172 */         prevText.append(")\">");
/* 173 */         prevText.append("上一页");
/* 174 */         prevText.append("</a>");
/*     */       } 
/* 176 */       if (nextDisabled.equalsIgnoreCase("")) {
/* 177 */         nextText.delete(0, prevText.length());
/* 178 */         nextText.append("<a class=a-but style=\"cursor:pointer\"");
/* 179 */         nextText.append(" onclick=\"goPage(window.location.href,");
/* 180 */         nextText.append(this.pageNo + 1);
/* 181 */         nextText.append(")\">");
/* 182 */         nextText.append("下一页");
/* 183 */         nextText.append("</a>");
/* 184 */         lastText.delete(0, lastText.length());
/* 185 */         lastText.append("<a class=a-but style=\"cursor:pointer\"");
/* 186 */         lastText.append(" onclick=\"goPage(window.location.href,");
/* 187 */         lastText.append(this.pageCount);
/* 188 */         lastText.append(")\">");
/* 189 */         lastText.append("[尾 &nbsp;页]");
/* 190 */         lastText.append("</a>");
/*     */       } 
/*     */ 
/*     */ 
/*     */ 
/*     */       
/* 196 */       StringBuffer pageSizeText = new StringBuffer();
/*     */ 
/*     */ 
/*     */       
/* 200 */       Integer[] sizes = { Integer.valueOf(10), Integer.valueOf(20), Integer.valueOf(50), Integer.valueOf(100), Integer.valueOf(200) };
/* 201 */       boolean isHaveSize = false;
/*     */       
/* 203 */       pageSizeText.append("<select name=\"rows\" id=\"rows\" onchange=\"inputGoToPage()\" style=\"width: auto;\">");
/*     */       
/* 205 */       for (int i = 0; i < sizes.length; i++) {
/*     */         
/* 207 */         pageSizeText.append("<option value='" + sizes[i] + "' ");
/* 208 */         if (sizes[i].intValue() == this.pageSize) {
/*     */           
/* 210 */           pageSizeText.append(" selected='selected' ");
/* 211 */           isHaveSize = true;
/*     */         } 
/* 213 */         pageSizeText.append(">" + sizes[i] + "</option>");
/*     */       } 
/*     */       
/* 216 */       if (!isHaveSize && this.pageSize != 0)
/*     */       {
/* 218 */         pageSizeText.append("<option value='" + this.pageSize + "' selected='selected'>" + this.pageSize + "</option>");
/*     */       }
/*     */       
/* 221 */       pageSizeText.append("</select>");
/*     */ 
/*     */ 
/*     */ 
/*     */       
/* 226 */       StringBuffer jumperText = new StringBuffer();
/* 227 */       jumperText.append("转到&nbsp;");
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */       
/* 238 */       jumperText.append("<input  style='width:30px;' type='text' name='tydic_inputgopage' id='tydic_inputgopage' value='" + this.pageNo + "' class='numericInput' decimalPlaces=0  /> 页 <input name='gobut' onclick=\"inputGoToPage()\" type='button' id='gobut' value='GO' class='button' />");
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */       
/* 244 */       String res = this.pageContext.getAttribute("res").toString();
/* 245 */       if (this.toExcel) {
/* 246 */         jumperText.append("&nbsp;<img src=\"" + res + "/images/xls.gif\" onclick=\"printToExcel()\" style='cursor:pointer;' alt='导出到Excel' />");
/*     */       }
/* 248 */       bar = "<table width='100%' border='0' height='25px' cellspacing='0' cellpadding='0'><tr><td align='left' width='300px' style='padding-left:10;' class='pageinfo'>共计：total条 \n共：<span id='t_page'>pages</span>页 \n第pageNo页 \n每页：pageSize条 </td><td  width='380px' align='center' class='pageinfo'>\nfirstText \nprevText \nnextText \nlastText\n </td><td align='right' width='300px' style='padding-right:10' class='pageinfo'>jumperText </td></tr></table>";
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */       
/* 256 */       bar = bar.replaceAll("pageSize", pageSizeText.toString());
/* 257 */       bar = bar.replaceAll("pages", String.valueOf(this.pageCount));
/* 258 */       bar = bar.replaceAll("pageNo", String.valueOf(this.pageNo));
/* 259 */       bar = bar.replaceAll("total", String.valueOf(this.total));
/* 260 */       bar = bar.replaceAll("firstText", firstText.toString());
/* 261 */       bar = bar.replaceAll("prevText", prevText.toString());
/* 262 */       bar = bar.replaceAll("nextText", nextText.toString());
/* 263 */       bar = bar.replaceAll("lastText", lastText.toString());
/* 264 */       bar = bar.replaceAll("jumperText", jumperText.toString());
/*     */     } 
/*     */     
/* 267 */     bar = bar + "\n<SCRIPT LANGUAGE=\"JavaScript\">\n function getGoPageFullUrl(url,pnumber,excel)\n { \n    var index = url.indexOf(\"?\");\n    if (index > 0) {\n       url = url.substring(0, index)\n    }\n    url += \"?page=\"+pnumber+\"&rows=\"+document.getElementById('rows').value;\n    url += \"" + getParamsFromCurrentURL(request, "page") + "\";" + " if(excel) url = url + '&printToExcel=printToExcel&isShowHref=" + isShowExcelHref() + "'; " + "\n return url;" + "}" + "\n function goPage(url, pnumber,excel) {;" + "\n url=getGoPageFullUrl(url,pnumber,excel);" + "\n    window.location=url;}" + "\n function JumpingPage(targ,selObj,restore){" + "\n  goPage(window.location.href,selObj.options[selObj.selectedIndex].value);" + "\n   if (restore) selObj.selectedIndex=0;" + "\n   return ;" + "\n }" + "//手写跳页 \n" + "function inputGoToPage(){" + "var tydicinputgopage = document.getElementById('tydic_inputgopage').value;" + "var total_page =  document.getElementById('t_page').innerHTML;" + "var total_page_num= parseInt(total_page);" + "" + "if(tydicinputgopage!=\"\"){" + "if(!isNaN(tydicinputgopage) && total_page_num>=parseInt(tydicinputgopage)){" + "goPage(window.location.href, tydicinputgopage);" + "}else{alert(\"请输入有效页码!\");document.getElementById('tydic_inputgopage').focus();}" + "}else{" + "alert('请输入页码！');document.getElementById('tydic_inputgopage').focus();" + "}}" + "\n" + " function printToExcel()\n" + " {\n" + "    goPage(window.location.href,1,'excel');\n" + " }\n" + "</script>";
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */     
/* 359 */     return bar;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static String getParamsFromCurrentURL(HttpServletRequest request, String exceptionParamNames) {
/* 370 */     String params = "";
/* 371 */     Enumeration<String> e = request.getParameterNames();
/* 372 */     label18: while (e.hasMoreElements()) {
/* 373 */       String key = e.nextElement();
/* 374 */       StringTokenizer st = new StringTokenizer(exceptionParamNames, ",");
/* 375 */       while (st.hasMoreTokens()) {
/* 376 */         String exceptionName = st.nextToken();
/* 377 */         if (key.equals(exceptionName)) {
/*     */           continue label18;
/*     */         }
/*     */       } 
/* 381 */       String value = request.getParameter(key);
/*     */       try {
/* 383 */         params = params + "&" + key + "=" + URLEncoder.encode(value, "utf-8");
/* 384 */       } catch (UnsupportedEncodingException e1) {
/*     */         
/* 386 */         e1.printStackTrace();
/*     */       } 
/*     */     } 
/* 389 */     return params;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private String trimURIParameter(String uri) {
/* 398 */     int len = uri.indexOf("?");
/* 399 */     String result = uri;
/* 400 */     if (len != -1) {
/* 401 */       result = result.substring(0, len);
/*     */     }
/* 403 */     return result;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public void setToExcel(boolean toExcel) {
/* 411 */     this.toExcel = toExcel;
/*     */   }
/*     */   
/*     */   public boolean isShowExcelHref() {
/* 415 */     return this.showExcelHref;
/*     */   }
/*     */   
/*     */   public void setShowExcelHref(boolean showExcelHref) {
/* 419 */     this.showExcelHref = showExcelHref;
/*     */   }
/*     */ }


/* Location:              D:\文件kjt\WEB-INF\lib\egrant-core-2.2.20240205.1659.jar!\com\iris\egrant\web\struts2\tags\PagerTag.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       1.1.3
 */